<?php
  /**
   * @author EVANDRO DE OLIVEIRA.
   * @category HELPER
   * @package VIEWS/HELPERS.
   * @since 17/03/2012.
   * @last_update 24/03/2012.
   * @copyright 2012.
   * @version 1.0.
   *
   */
  class Zend_View_Helper_Menu extends Zend_View_Helper_Abstract{
    public function menu(){
      $objAuthNamespace = new Zend_Session_Namespace('Zend_Auth');
      
      $intIdPerfil = $objAuthNamespace->idPerfil;
       
      $objDaoMenu = new Application_Model_Menu();
      
      $arrResultMenu = $objDaoMenu->getMenu($intIdPerfil);
      ?>
      <div id="header-navigation">
        <ul class="menu">
          <?php 
            if(Zend_Auth::getInstance()->hasIdentity() && Zend_Auth::getInstance()->getIdentity()->session_initialized){
            	if($arrResultMenu){
	            	foreach($arrResultMenu as $arrData){
	          	  	$objData = (object)$arrData;
	          	  	if($objData->idParent == 0){
	          	  	  ?>
	          	  	  <li class="top">
	          	  	    <?php
	          	  	    $strDsMenu = "<span>" . utf8_encode($objData->ds_menu) . "</span>";
	          	  	      
	          	  	    $this->view->link($objData->ds_controller, $objData->ds_action, $strDsMenu, false, 'top_link', 'color:#FFF;');
	          	  	      
	          	  	    $arrResultParent = $objDaoMenu->getParentMenu($intIdPerfil, $objData->idMenu);
	          	  	      
	            	      if($arrResultParent){
	                      ?>
	            	        <ul class="sub">
		            	        <?php
		            	          foreach($arrResultParent as $arrDataParent){
		            	        	  $objDataParent = (object)$arrDataParent;
		            	        	  
		            	      	    ?>
		                          <li>
	                              <?php 
	                                $this->view->link($objDataParent->ds_controller, $objDataParent->ds_action, utf8_encode($objDataParent->ds_menu), false, 'fly');
	                              ?>
	                            </li>
		            	      	    <?php
		            	          }
		            	        ?>
		            	      </ul>  
	            	        <?php  
	            	      }?>
	                  </li>
	          	  	  <?php
	          	    } 	
	              }
            	}
              ?>
              <li class="top">
                <?php echo $this->view->link('account', 'logout', 'Sair', false, 'top_link', 'color:#FFF; padding-right: 10px; padding-left: 10px;')?>
              </li>
              <?php
            }   	
          ?>
        </ul>
      </div>
      <?php
    }
  }  